﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite.admin.Case
{
    public partial class EditCaseInfoForm : BasicPage
    {
        public int Id;

        private readonly CaseBLL _bll = new CaseBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request.Params["id"] as string, out this.Id))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }
            if (!Page.IsPostBack)
            {
                chkLoginLevel("editCase");
                ShowInfo(this.Id);
            }
        }

        private void ShowInfo(int id)
        {
            var model = _bll.GetCaseInfo(id);
            txtCaseName.Text = model.CaseName;
            txtCaseRemark.Text = model.CaseRemark;
            txtCaseDummyImg.Text = model.CaseDummyImg;
            txtCaseImg.Text = model.CaseImg;
            if (model.IsRec == 1)
            {
                cblItem.Items[0].Selected = true;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var model = new CaseInfo
            {
                CaseId = Id,
                CaseName = txtCaseName.Text.Trim(),
                CaseRemark = txtCaseRemark.Text.Trim(),
                CaseDummyImg = txtCaseDummyImg.Text.Trim(),
                CaseImg = txtCaseImg.Text.Trim(),
                IsRec = 0
            };
            model.IsRec = cblItem.Items[0].Selected ? 1 : 0;
            model.ModifyUser = "李波";
            model.ModifyTime = DateTime.Now;
            if (_bll.Add(model))
            {
                JscriptPrint("修改成功！", "CaseMasteRForm.aspx", "Success");
            }
            else
            {
                JscriptPrint("修改失败！", "", "Error");
            }
        }
    }
}